package com.li.day.day17;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Update extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Connection co=null;
        PreparedStatement pp=null;
        req.setCharacterEncoding("gbk");
        resp.setContentType("text/html;charset=utf-8");
        Object name3 = req.getSession().getAttribute("name3");
        String mima1 = req.getParameter("mima1");
        String mima2 = req.getParameter("mima2");
        String s = "update ppro set user_password='" + mima1 + "' where user_name='" + name3 + "'";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
             co = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/p3kao", "root", "root");
             pp = co.prepareStatement(s);
                          if (mima1.equals(mima2)){
                              pp.executeUpdate();
                     req.getRequestDispatcher("Denglu").forward(req,resp);
             }else {
                 resp.getWriter().write("请检查密码是否一致");
             }



        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
